
//---------------------------------------------------------------------------
#include "entities/pg1_map.h"
//---------------------------------------------------------------------------
#include "rendering/pg1_renderer.h"
//---------------------------------------------------------------------------
using namespace pg1;
//---------------------------------------------------------------------------
const Map::Tile Map::NoTile(false);
//---------------------------------------------------------------------------
Map::Map ()
:
Entity2D(),
m_apkMap(NULL),
m_uiWidth(0),
m_uiHeight(0),
m_kTexture(NoTexture)
{
	// nothing to do 
}
//---------------------------------------------------------------------------
Map::~Map ()
{
	// nothing to do
}
//---------------------------------------------------------------------------
Map::Tile::Tile (bool bCollides)
:
m_bCollides(bCollides)
{
	// nothing to do
}
//---------------------------------------------------------------------------
Map::Tile::Tile (const Tile& rkTile)
:
m_bCollides( rkTile.collides() )
{
	// nothing to do
}
//---------------------------------------------------------------------------
const Map::Tile& Map::tile (unsigned int uiId) const
{
	std::map<unsigned int, Tile>::const_iterator it = m_kTiles.find(uiId);
	if( it != m_kTiles.end() )
	{
		return (*it).second;
	}
	else
	{
		return NoTile;
	}
}
//---------------------------------------------------------------------------
void Map::setTile (unsigned int uiId, const Map::Tile& rkTile)
{
	m_kTiles[uiId] = Tile( rkTile.collides() );
}
//---------------------------------------------------------------------------
void Map::setDimensions (size_t uiWidth, size_t uiHeight)
{
	// delete old tiles
	for(unsigned int i=0;i<m_uiWidth; i++)
	{
		delete[] m_apkMap[i];
	}

	delete[] m_apkMap;

	// create the new ones
	m_uiWidth = uiWidth;
	m_uiHeight = uiHeight;

	m_apkMap = new Tile*[m_uiWidth];
	for(unsigned int i=0;i<uiWidth; i++)
	{
		m_apkMap[i] = new Tile[m_uiHeight];
		for(unsigned int j=0;j<uiWidth; j++)
		{
			m_apkMap[i][j] = NoTile;
		}
	}
}
//---------------------------------------------------------------------------
void Map::setTileDimensions (size_t uiTileWidth, size_t uiTileHeight)
{
	m_uiTileWidth = uiTileWidth;
	m_uiTileHeight = uiTileHeight;
}
//---------------------------------------------------------------------------
void Map::draw (Renderer& rkRenderer) const
{
	rkRenderer.setCurrentTexture(m_kTexture);
	rkRenderer.setMatrix( World, transformationMatrix() );

}
//---------------------------------------------------------------------------
